//首页切换推荐和最新
const resContents = document.querySelectorAll('.resContent')
document.querySelector('.leftTitle').addEventListener('click', e => {
	// console.log(e.target.dataset.id)
	if (document.querySelector('.leftTitle .color')) document.querySelector('.leftTitle .color').classList.remove('color')
	e.target.classList.add('color')
	for (let i = 0; i < resContents.length; i++) {
		resContents[i].classList.add('hidden')
	}
	resContents[e.target.dataset.id].classList.remove('hidden')
})
//查询推荐文章列表 渲染
let i=1
async function getRecList(i) {
	const res = await axios({
		url: 'cdArticle/getArticleList',
		method: 'post',
		data: {
			pageNo: i,
			pageSize: 10,
			newFlag: ""
		}
	})
	const list = res.data.result.list
	// console.log(list)
	document.querySelector('.resContent').innerHTML += list.map(item => {
		return `
		<a  href="/ysyApi/app/html/article/${item.id}">
			<li>
				<h3>${item.title}</h3>
					<div class="center">
						<img src="${item.coverImg}" alt="" title='${item.title}'>
						<p>${item.descript}</p>
					</div>
					<div class="details">
						<span>${item.createTime}</span>
						<div class="point"></div>
						<span>${item.brands[0].bname}</span>
						<div class="point"></div>
						<span>${item.homeCategory}</span>
						<div class="point"></div>
						<span>${item.readNum}阅读</span>
					</div>
			</li>
		</a>
		`
	}).join('')
}
getRecList(i)

// 查询最新文章列表 渲染
async function getNewList(i){
	const res=await axios({
		url:'cdArticle/getArticleList',
		method:'post',
		data:{
			pageNo: i,
			pageSize: 10,
			newFlag: "flag"
		}
	})
	// console.log(res.data.result.list)
	const list=res.data.result.list
	document.querySelector('.uptodata').innerHTML+= list.map(item=>{
		return `
		<a href="/ysyApi/app/html/article/${item.id}">
			<li>
				<h3>${item.title}</h3>
				<div class="center">
					<div class="img">
						<img src="${item.coverImg}" alt="" title='${item.title}'>
					</div>
					<p>${item.descript}
					</p>
				</div>
				<div class="details">
					<span>${item.createTime}</span>
					<div class="point"></div>
					<span>${item.brands[0].bname}</span>
					<div class="point"></div>
					<span>${item.homeCategory}</span>
					<div class="point"></div>
					<span>${item.readNum}阅读</span>
				</div>
			</li>
		</a>`
	}).join('')
}
getNewList(i)

window.addEventListener('scroll', () => {
	// console.log(document.documentElement.scrollTop)
	// console.log(window.innerHeight)//屏幕
	// console.log(document.body.scrollHeight)
	if (document.documentElement.scrollTop + window.innerHeight === document.body.scrollHeight) {
		i++
		getRecList(i)
		getNewList(i)
	}
})